Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Why does it print "undefined" on the console?

I have the following JavaScript code:

please help

let statement = ['Kim is a good, kind and smart boy'];
    
let kim = {
  message () {
    console.log(statement);
  },
  interest () {
    console.log('sports');
  }
}
console.log(kim.message());
console.log(kim.interest());

I expect that it should print this output:

[ 'Kim is a good, kind and smart boy' ]
sports

But instead, it prints the following:

[ 'Kim is a good, kind and smart boy' ]
undefined
sports
undefined

Why does it print "undefined" after each function within the method?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I suppose you're calling console.log(kim.message()); and console.log(kim.interest());

console.log prints the return value of the passed function but because both the function don't have a return statement console.log prints undefined that's way you see those additional undefined logs.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!